<!DOCTYPE html>
<html>

	<head>
		<meta charset="UTF-8">
		<link rel="stylesheet" href="../../../res/layui/css/layui.css" media="all" type="text/css">
		<script src="../../../res/js/jquery-3.1.1.min.js" type="text/javascript"
				charset="utf-8"></script>
		<script src="../../../res/js/login_common.js" charset="utf-8"></script>
		<script src="../../../res/layui/layui.js" charset="utf-8"></script>
		<script src="../../../res/layui/layui.all.js" charset="utf-8"></script>
		<script>
            $.ajaxSetup({
                async : false
            });
			$(function(){
                var coachId=loginObj.user.userId;
                $("#userId").val(coachId);
			})
		</script>

	</head>

	<body>
		<div class="cBody">
			<form class="layui-form" action="" id="formDId" lay-filter="example" method="post" enctype="multipart/form-data">
				<input type="hidden" id="userId" name="userId">
				<div class="layui-form-item">
					<label class="layui-form-label">原始密码</label>
					<div class="layui-input-inline shortInput">
						<input type="password" name="userPwd" id="userPwd" required lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">新密码</label>
					<div class="layui-input-inline shortInput">
						<input type="password" name="userPwd1" id="userPwd1" required lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>
				<div class="layui-form-item">
					<label class="layui-form-label">确认新密码</label>
					<div class="layui-input-inline shortInput">
						<input type="password" name="userPwd2" id="userPwd2" required lay-verify="required" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<label class="layui-form-label">电表住址</label>
					<div class="layui-input-inline shortInput">
						<input type="text" style="width: 380px" name="userAddress"  lay-verify="userAddress" autocomplete="off" class="layui-input">
					</div>
				</div>

				<div class="layui-form-item">
					<div class="layui-input-block">
						<button type="button" class="layui-btn site-demo-active" lay-submit lay-filter="formDemo">立即提交</button>
						<button type="reset" class="layui-btn layui-btn-primary">重置</button>
					</div>
				</div>
			</form>

			<script>

                var form=null;
                layui.use('form', function() {
                    form = layui.form;
                    //监听提交
                    form.on('submit(formDemo)', function (data) {
                        var urltwo="../../../UserController/selectPswd";
                        var datatwo={userId:$("#userId").val(),userPwd:$("#userPwd").val()};
                        $.post(urltwo,datatwo,function(objs){
                            if(objs.num===0){
                                layer.msg(objs.msg);
                                return false;
							}else{
                                if($("#userPwd2").val()!=$("#userPwd1").val()){
                                    layer.msg("新密码和确认密码不一致");
                                    return false;
								}
                                // 单击之后提交按钮不可选,防止重复提交
                                var DISABLED = 'layui-btn-disabled';
                                // 增加样式
                                $('.site-demo-active').addClass(DISABLED);
                                // 增加属性
                                $('.site-demo-active').attr('disabled', 'disabled');

                                var formData = new FormData(document.getElementById("formDId"));
                                var url = "../../../UserController/updateState";
                                $.ajax({
                                    url: url,
                                    type: "post",
                                    data: formData,
                                    processData: false,
                                    contentType: false,
                                    dataType: "json",
                                    success: function (obj) {
                                        if (obj.num == 1) {
                                            layer.msg(obj.msg, {
                                                icon: 1,
                                                time: 1000 //1秒关闭(如果不配置默认三秒)
                                            }, function () {
                                                //关闭当前层
                                                //当你在iframe页面关闭自身时
                                                parent.layui.table.reload("test");
                                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                                parent.layer.close(index); //再执行关闭
                                                //刷新父页面

                                                //parent.location.reload();
                                            });
                                            return false;
                                        }
                                    },
                                    error: function (e) {
                                        layer.msg("错误！！");
                                    }
                                });
                                return false;
							}
						},"json");

                    });
                })
			</script>

		</div>
	</body>

</html>